<script>
export default {
  emits: ['complete'],
  name: "UserForm",
  data() {
    return {
      user: {
        name: null,
        gender: null,
        age: null,
        is_active: null,
      }
    }
  },
  methods: {
    save() {
      this.$http.post('save', this.user)
          .then(res => {
            this.$message.success('save success !')
          })
          .finally(() => {
            this.user = {}
            this.$emit('complete')
          })
    },
    setUser(user) {
      this.user = user || {}
    }
  }
}
</script>

<template>
  {{ user }}
  <el-card>
    <template #header>
      User Information
    </template>
    <el-form>
      <el-form-item label="name">
        <el-input v-model="user['name']"></el-input>
      </el-form-item>
      <el-form-item label="gender">
        <el-select v-model="user['gender']">
          <el-option label="Female" value="F"></el-option>
          <el-option label="Male" value="M"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="age">
        <el-input-number v-model="user['age']"></el-input-number>
      </el-form-item>
      <el-form-item label="is_active">
        <el-checkbox border v-model="user.is_active">True</el-checkbox>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="success" @click="save">Save</el-button>
    </template>
  </el-card>


</template>

<style scoped>

</style>